(function () {
	//定义评分模板字符串
	var itemTmpl = '<div class="star-score">$starstr</div>';

	function _getStars(){
		var _score = this.score.toString();

		//4.4分 将带小数点的分数值,通过小数点分割成数组,数组有两个值
		var scoreArr = _score.split('.');

		//满星数量:数组值1
		var fullStar = parseInt(scoreArr[0]);

		//半星或者0星数量:数组值2
		var halfStar = parseInt(scoreArr[1]) >= 5 ? 1 : 0 ;

		//0星数量
		var nullStar = 5 - fullStar - halfStar;

		//定义星星内容:空字符串
		var starstr = '';

		//循环遍历添加:满星字符串
		for (var i = 0;i<fullStar;i++){
			starstr += '<div class="star fullStar"></div>';
		}

		//循环遍历添加:半星字符串
		for (var j= 0;j<halfStar; j++){
			starstr += '<div class="star halfStar"></div>';
		}

		//循环遍历添加:0星字符串
		for (var k = 0;k<nullStar;k++){
			starstr += '<div class="star nullStar"></div>';
		}

		//替换占位符为完整的星星字符串
		return itemTmpl.replace('$starstr',starstr);

	}

	//将starScores方法挂到全局window上
	window.starScores = function(score){
		this.score = score || '';
		this.getStars = _getStars;
	}

})();